home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F39886_elimError2.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-02-06  |  4.6 KB  |  136 lines

  1. <xsl:stylesheet version="1.0"
  2. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:roundLog2="roundLog2"
  4. exclude-result-prefixes="roundLog2"
  5. >
  6.   <xsl:import href="roundLog2.xsl"/>
  7.   
  8.   <xsl:template name="elimError">
  9.     <xsl:param name="pList" select="/.."/>
  10.     <xsl:param name="pOrder" select="-9999999"/>
  11.     <xsl:param name="pv2__N" select="0"/>
  12.     
  13.     <xsl:choose>
  14.       <xsl:when test="count($pList) < 3">
  15.         <xsl:copy-of select="$pList"/>
  16.       </xsl:when>
  17.       <xsl:otherwise>
  18.         <xsl:variable name="vOrder">
  19.             <xsl:choose>
  20.               <xsl:when test="$pOrder < -9999998">
  21.                 <xsl:call-template name="getOrder">
  22.                   <xsl:with-param name="pList" select="$pList"/>
  23.                 </xsl:call-template>
  24.               </xsl:when>
  25.               <xsl:otherwise>
  26.                 <xsl:value-of select="$pOrder"/>
  27.               </xsl:otherwise>
  28.             </xsl:choose>
  29.         </xsl:variable> 
  30.       
  31.         <xsl:variable name="v2__N">
  32.           <xsl:choose>
  33.               <xsl:when test="$pv2__N = 0">
  34.                   <xsl:call-template name="pow">
  35.                     <xsl:with-param name="base" select="2"/>
  36.                     <xsl:with-param name="pow" select="$vOrder"/>
  37.                   </xsl:call-template>
  38.               </xsl:when>
  39.               <xsl:otherwise>
  40.                   <xsl:value-of select="$pv2__N"/>
  41.               </xsl:otherwise>
  42.           </xsl:choose>
  43.         </xsl:variable>
  44.         
  45.         <xsl:element name="{name($pList[1])}">
  46.           <xsl:value-of select="($pList[2] * $v2__N - $pList[1]) 
  47.                                  div 
  48.                                   ($v2__N - 1)"/>
  49.         </xsl:element>
  50.         
  51.         <xsl:variable name="vNewList" select="$pList[position() > 1]"/>
  52.         
  53.         <xsl:variable name="vNewOrder">
  54.             <xsl:call-template name="getOrder">
  55.               <xsl:with-param name="pList" select="$vNewList"/>
  56.             </xsl:call-template>
  57.         </xsl:variable> 
  58.         <xsl:call-template name="elimError">
  59.             <xsl:with-param name="pList" select="$vNewList"/>
  60.             <xsl:with-param name="pOrder" select="$vNewOrder"/>
  61.             <xsl:with-param name="pv2__N" select="$v2__N"/>
  62.         </xsl:call-template>
  63.         
  64.       </xsl:otherwise>
  65.     </xsl:choose>
  66.   </xsl:template>
  67.   
  68.   <xsl:template name="getOrder">
  69.     <xsl:param name="pList" select="/.."/>
  70.     
  71.     <xsl:choose>
  72.       <xsl:when test="count($pList) < 3">1</xsl:when>
  73.       <xsl:otherwise>
  74.         <xsl:variable name="v1" select="($pList[1] - $pList[3])
  75.                                        div 
  76.                                          ($pList[2] - $pList[3])
  77.                                          - 1"/>
  78.         <xsl:variable name="v2">
  79.           <xsl:choose>
  80.             <xsl:when test="$v1 > 0">
  81.               <xsl:value-of select="$v1"/>
  82.             </xsl:when>
  83.             <xsl:when test="$v1 < 0">
  84.               <xsl:value-of select="(-1) * $v1"/>          
  85.             </xsl:when>
  86.             <xsl:otherwise>1</xsl:otherwise>
  87.           </xsl:choose>
  88.         </xsl:variable>
  89.         
  90.         <xsl:value-of select="roundLog2:roundLog2(string($v2))"/>
  91.       </xsl:otherwise>
  92.     </xsl:choose>
  93.   </xsl:template>
  94.   
  95.    <xsl:template name="pow">
  96.         <xsl:param name="base" select="1"/>
  97.         <xsl:param name="pow" select="0"/>
  98.         <xsl:param name="tmpResult" select="1"/>
  99.  
  100.         <xsl:variable name="result">
  101.             <xsl:choose>
  102.                 <xsl:when test="$pow >= 0">
  103.                     <xsl:value-of select="$tmpResult * $base"/>
  104.                 </xsl:when>
  105.                 <xsl:otherwise>
  106.                     <xsl:value-of select="$tmpResult div $base"/>
  107.                 </xsl:otherwise>
  108.            </xsl:choose>
  109.         </xsl:variable>
  110.  
  111.         <xsl:variable name="incr">
  112.             <xsl:choose>
  113.                 <xsl:when test="$pow >= 0">
  114.                     <xsl:value-of select="- 1"/>
  115.                 </xsl:when>
  116.                 <xsl:otherwise>
  117.                     <xsl:value-of select="1"/>
  118.                 </xsl:otherwise>
  119.             </xsl:choose>
  120.         </xsl:variable>
  121.  
  122.         <xsl:choose>
  123.             <xsl:when test="$pow = 0">
  124.                 <xsl:value-of select="$tmpResult"/>
  125.             </xsl:when>
  126.             <xsl:otherwise>
  127.                 <xsl:call-template name="pow">
  128.                     <xsl:with-param name="base" select="$base"/>
  129.                     <xsl:with-param name="pow" select="$pow + $incr"/>
  130.                     <xsl:with-param name="tmpResult" select="$result"/>
  131.                 </xsl:call-template>
  132.             </xsl:otherwise>
  133.         </xsl:choose>
  134.     </xsl:template>
  135.   
  136. </xsl:stylesheet>